layui.use('layer', function() {
    layer = layui.layer;
    // 用户关注
    $(".follow").click(function () {
        // 被关注者id
        var uid = $(this).attr("data-id");
        // 关注者id
        var nid = $(this).attr("use-id");
        showFollow(uid,nid);
    });

    // 用户关注 AJAX
    function showFollow(uid,nid) {
        $.ajax({
            url: '../dofollow',
            type: 'post',
            data: {'uid': uid, 'nid': nid},
            dataType: 'json',
            success: function (data) {
                if (data.status) {
                    layer.msg("关注成功", {offset:'50%',icon: 6, time: 500}, function () {
                        location.reload(true);
                    });
                } else {
                    layer.msg("正在关注，客观莫急", {offset:'50%',icon: 6, time: 500}, function () {
                        // 关闭模态框
                        x_admin_close();
                        // 刷新页面
                        parent.location.reload();
                    });
                }
            }
        });
        return;
    }


    // 用户取消关注
    $(".disfollow").click(function () {
        // 被关注者id
        var uid = $(this).attr("data-id");
        // 关注者id
        var nid = $(this).attr("use-id");
        showDisFollow(uid,nid);
    });

    // 用户取消关注 AJAX
    function showDisFollow(uid,nid) {
        $.ajax({
            url: '../dodisfollow',
            type: 'post',
            data: {'uid': uid, 'nid': nid},
            dataType: 'json',
            success: function (data) {
                if (data.status) {
                    layer.msg("取消关注成功", {offset:'50%',icon: 6, time: 500}, function () {
                        location.reload(true);
                    });
                } else {
                    layer.msg("正在取消，客官莫急。。", {offset:'50%',icon: 6, time: 500}, function () {
                        // 关闭模态框
                        x_admin_close();
                        // 刷新页面
                        parent.location.reload();
                    });
                }
            }
        });
        return;
    }
});


